//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics.Contracts;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media;

namespace OpenLS.Media
{
    public class ImageExtension : MarkupExtension
    {
        private readonly ImageSource _imageSource;

        public ImageExtension(string source)
        {
            string actualSource = string.Format("pack://application:,,/OpenLS.Media;component/{0}.png", source);
            try
            {

                _imageSource = new ImageSourceConverter().ConvertFrom(actualSource) as ImageSource;
            }
            catch (Exception)
            {
                // Contract.Assert(false);
                throw;
            }

        }

      

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var result = new Image { Stretch = Stretch.Uniform, Source = _imageSource };
          //  if (Width != null)
           //     result.Width = Width.Value;
         //   if (Height != null)
           //     result.Height = Height.Value;
            return result;

        }
    }
}
